package edu.ucsd.ccdb.tagPopup.summaryPane;

import java.util.ArrayList;
import java.util.List;

import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import edu.ucsd.ccdb.generalDataType.TagDataValue;
import edu.ucsd.ccdb.tagPopup.dataType.CCDBTagElementDisplay;
import edu.ucsd.irods.IRODSFileString;
import edu.ucsd.irods.SQLDBQuery;

public class CCDBTagSummaryPane extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public CCDBTagSummaryPane ( String username, JPanel source, Integer  MPID, IRODSFileString file) {
		
		// getdata on all ccdb tags 		
		List <TagDataValue> listData = getDetailTabsOnSelectedFile(file.getAbsolutePath());
		
		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		
		add (new JLabel("CCDB Tags: ") );
		for (TagDataValue data: listData) {
			add ( new CCDBTagElementDisplay( username, source, MPID, file, data) );
		}		
	}
	
	private List<TagDataValue> getDetailTabsOnSelectedFile (String filePath ) {
		
		List<TagDataValue> data = null;
		try {
			data = SQLDBQuery.getSumaryInfo(filePath);
		} catch (Exception e) {
			e.printStackTrace();			
		}
		
		return data;
	}
	
	public static List<String> getBriefSummary (Integer MPID, IRODSFileString file ) {
		
		List<TagDataValue> list = new ArrayList<TagDataValue>();
		
		try {
			list = SQLDBQuery.getSumaryInfo( file.getAbsolutePath() );
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		List<String> result = new ArrayList<String>();
		
		for (TagDataValue element: list ) {
			result.add(element.getName() );
		}
		
		return result;
	}
}
